<?php
/*
 * Created on 07.12.2008
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

include_once 'JF_AbstractController.php';


class JF_DirectController extends JF_AbstractController {

	public function view () {

	}

	final public function execute() {
		try {
			$oRM 			= new ReflectionMethod($this, $this->getParameter('method'));
			$aArguments 	= (array)$this->getParameter('arguments');
			$aParameters	= $oRM->getParameters();
			$isCorrect 		= true;
			for ($i = 0; $i < count($aParameters); $i++) {
				if (!array_key_exists($i, $aArguments)) {
					$oClass 		= new ReflectionClass($aParameters[$i]->getClass()->getName());
					$aArguments[$i] = $oClass->newInstance();
				}

				$sSourceType 	= $aParameters[$i]->getClass()->getName();
				if (!$aArguments[$i] instanceof $sSourceType) {
					$isCorrect = false;
				}

			}

			if ($isCorrect) {
				if (empty($aArguments)) {
					$oView = $oRM->invoke($this);
				}
				else {
					$oView = $oRM->invokeArgs($this, $aArguments);
				}

			}


			if ($oView instanceof JF_IView) {
				$oView->render();
			}

		}
		catch (ReflectionException $oRE) {
			$oController = JF_ReflectionUtil::newInstance(
					$this->getParameter('404Controller'),
					array(),
					'JF_IController'
					);
			$oController->setURI($this->getURI());
			$oController->execute();
		}

	}

}